package com.demo.springboothexadecimalconversion.service.DecodeImpl;

import com.alibaba.fastjson.JSONObject;
import com.demo.springboothexadecimalconversion.service.Decode;
import org.springframework.stereotype.Component;

/**
 * @author Hanson
 * @date 2022/11/15 15:36
 */
@Component
public class DeviceInfoDecodeImpl implements Decode {
    @Override
    public JSONObject Decode(String str) {

        JSONObject jo = new JSONObject();
        String timeStampHex = str.substring(5, 16);
        String SNHex = str.substring(17,24);
        String msgFrameHex = str.substring(24,26);
        String protocolVersionHex = str.substring(26,28);
        String softwareVersionHex = str.substring(28,32);
        String hardwareVersionHex = str.substring(32,36);
        String ModelTypeHex = str.substring(36,38);
        long timeStamp = Long.parseLong(timeStampHex, 16);
        Integer SN = Integer.valueOf(SNHex, 16);
        Integer msgFrame = Integer.valueOf(msgFrameHex, 16);
        Integer protocolVersion = Integer.valueOf(protocolVersionHex, 16);
        Integer softwareVersion = Integer.valueOf(softwareVersionHex, 16);
        Integer hardwareVersion = Integer.valueOf(hardwareVersionHex, 16);
        Integer ModelType = Integer.valueOf(ModelTypeHex, 16);
        jo.put("SN",SN);
        jo.put("msgFrame",msgFrame);
        jo.put("protocolVersion",protocolVersion);
        jo.put("softwareVersion",softwareVersion);
        jo.put("hardwareVersion",hardwareVersion);
        jo.put("ModelType",ModelType);
        jo.put("timeStamp",timeStamp);
        return jo;
    }
}
